#!/usr/bin/env python
# -*- coding:utf-8 -*-
import ConfigParser
import hashlib

def wrapper_login(func):
    def login():
        CardInfoFile=ConfigParser.ConfigParser()
        CardInfoFile.read('info.txt')
        CardRealNumber=CardInfoFile.get('login','cardnum')
        CardRealPass=CardInfoFile.get('login','cardpass')
        while True:
            UserInputCardNumber=raw_input("please input your card number:")
            UserInputCardPass=raw_input("please input card password:")#start把用户输入的密码转换成md5
            hash=hashlib.md5()
            hash.update(UserInputCardPass)
            UserInputCardPass=hash.hexdigest()#end
            FailLoginNumber=CardInfoFile.getint('login','failnum')#登录次数失败了会变，所以放在循环里；
            if UserInputCardNumber==CardRealNumber :
                if FailLoginNumber>=3:
                    print "Login failure Number is too many!"
                    break
                if UserInputCardPass==CardRealPass:
                    func()
                    return True
                else:
                    print 'Password invalid!'
                    CardInfoFile.set('login','failnum',str(FailLoginNumber+1))
                    print CardInfoFile.get('login','failnum')
                    CardInfoFile.write(open('info.txt','w'))
                    print CardInfoFile.get('login','failnum')
            else:
                print "CreditCard Number is invalid!"
    return login

@wrapper_login
def func1():
    print "ok"

func1()